package com.strive.common.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.strive.common.lock.DistributedLock;

/**
 * @description:
 * @author: bingcun.chen
 * @Date: 2022/2/23 14:28
 * @Version 1.0
 */
public interface ISuperService<T> extends IService<T> {
    /**
     * 幂等性新增记录
     * @param entity 实体对象
     * @param locker 锁实例
     * @param lockKey 锁的key
     * @param countWrapper 判断是否存在的条件
     * @param msg 对象已经存在的实例
     * @return
     * @throws Exception
     */
    boolean saveIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper, String msg) throws Exception;

    default boolean saveIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper) throws Exception {
        return this.saveIdempotency(entity,locker,lockKey,countWrapper,null);
    }

    /**
     * 幂等性新增或者更新记录
     * @param entity 实体对象
     * @param locker 锁实例
     * @param lockKey 锁的key
     * @param countWrapper 判断是否存在的条件
     * @param msg 对象已经存在提示
     * @return
     * @throws Exception
     */
    boolean saveOrUpdateIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper, String msg) throws Exception;

    default boolean saveOrUpdateIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper) throws Exception {
        return this.saveIdempotency(entity,locker,lockKey,countWrapper,null);
    }
}
